import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Client from '@/client'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/Register',
    component: () => import('@/views/Client/Register'),
    hidden: true,
    meta: {
      title: '前台',
      type: "Client",

    },
  },
  {
    path: '/404',

    component: () => import('@/views/404'),
    hidden: true,
    meta: {
      type: "foreground",
    },
  },


  { path: '*', redirect: '/', hidden: true }
]
export const constantHomeRoutes = [
  {
    path: '/Client/Index',
    component: Client,
    redirect: "/Client/Home",
    meta: {
      title: '前台',
      type: "Client",

    },
    children: [{
      path: '/Client/Home',
      component: () => import('@/views/Client/Home'),
      name: 'Home',
      hidden: true,
      meta: {
        type: "Client",
        title: '首页',

      }
    }]
  },
]


export const asyncRoutes = [
  {
    path: '/home/index',
    meta: {
      roles: [0, 2],
    },
    component: Layout,
    meta: {
      title: '前台',
      noCache: true,
      roles: [0, 2],
    }
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    meta: {
      roles: [0, 2],
    },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'dashboard',
      meta: {
        roles: [0, 2],
        title: '控制台',
        noCache: true
      }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/Admin/UserList',
    meta: {
      title: '用户管理',
      icon: "el-icon-s-custom",
      roles: [0],
    },
    children: [{
      path: 'UserList',
      component: () => import('@/views/Admin/UserList'),
      name: 'UserList',
      meta: {
        title: '用户',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Announcement',
    component: Layout,
    redirect: '/Admin/AnnouncementList',
    meta: {
      title: '公告管理',
      icon: "el-icon-monitor",
      roles: [0],
    },
    children: [{
      path: 'AnnouncementList',
      component: () => import('@/views/Admin/AnnouncementList'),
      name: 'AnnouncementList',
      meta: {
        title: '公告信息',
        roles: [0],
        noCache: true
      }
    }]
  },

  {
    path: '/ArticleInfo',
    component: Layout,
    redirect: '/Admin/ArticleInfoList',
    meta: {
      title: '资讯管理',
      icon: "el-icon-files",
      roles: [0],
    },
    children: [{
      path: 'ArticleInfoList',
      component: () => import('@/views/Admin/ArticleInfoList'),
      name: 'ArticleInfoList',
      meta: {
        title: '资讯信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/ArticleType',
    component: Layout,
    redirect: '/Admin/ArticleTypeList',
    meta: {
      title: '资讯类型管理',
      icon: "el-icon-connection",
      roles: [0],
    },
    children: [{
      path: 'ArticleTypeList',
      component: () => import('@/views/Admin/ArticleTypeList'),
      name: 'ArticleTypeList',
      meta: {
        title: '资讯类型信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Banner',
    component: Layout,
    redirect: '/Admin/BannerList',
    meta: {
      title: '门户封面管理',
      icon: "el-icon-picture",
      roles: [0],
    },
    children: [{
      path: 'BannerList',
      component: () => import('@/views/Admin/BannerList'),
      name: 'BannerList',
      meta: {
        title: '门户封面信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/CensusInfoPerson',
    component: Layout,
    redirect: '/Admin/CensusInfoPersonList',
    meta: {
      title: '户籍信息管理',
      icon: "el-icon-s-data",
      roles: [0],
    },
    children: [{
      path: 'CensusInfoPersonList',
      component: () => import('@/views/Admin/CensusInfoPersonList'),
      name: 'CensusInfoPersonList',
      meta: {
        title: '户籍个人信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Explain',
    component: Layout,
    redirect: '/Admin/ExplainList',
    meta: {
      title: '申述管理',
      icon: "el-icon-tickets",
      roles: [0],
    },
    children: [{
      path: 'ExplainList',
      component: () => import('@/views/Admin/ExplainList'),
      name: 'ExplainList',
      meta: {
        title: '申述信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/Household',
    component: Layout,
    redirect: '/Admin/HouseholdList',
    meta: {
      title: '户口信息管理',
      icon: "el-icon-paperclip",
      roles: [0],
    },
    children: [{
      path: 'HouseholdList',
      component: () => import('@/views/Admin/HouseholdList'),
      name: 'HouseholdList',
      meta: {
        title: '户口信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/HouseholdIn',
    component: Layout,
    redirect: '/Admin/HouseholdInList',
    meta: {
      title: '户口迁入管理',
      icon: "el-icon-coordinate",
      roles: [0],
    },
    children: [{
      path: 'HouseholdInList',
      component: () => import('@/views/Admin/HouseholdInList'),
      name: 'HouseholdInList',
      meta: {
        title: '户口迁入信息',
        roles: [0],
        noCache: true
      }
    }]
  },
  {
    path: '/HouseholdOut',
    component: Layout,
    redirect: '/Admin/HouseholdOutList',
    meta: {
      title: '户口迁出管理',
      icon: "el-icon-school",
      roles: [0],
    },
    children: [{
      path: 'HouseholdOutList',
      component: () => import('@/views/Admin/HouseholdOutList'),
      name: 'HouseholdOutList',
      meta: {
        title: '户口迁出信息',
        roles: [0],
        noCache: true
      }
    }]
  },




]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...constantHomeRoutes, ...asyncRoutes]
})

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
